<!-- 车辆出厂 -->
<template>
    <div>
        <el-form :rules="rules" :model="cars" label-width="120px" class="demo-ruleForm">
            <el-form-item label="请输入车牌号" prop="carId">
                <el-input v-model="cars.carId" autocomplete="off" />
            </el-form-item>
            <el-form-item label="是不是我们的VIP啦" prop="carId">
                <el-input v-model="cars.vip" autocomplete="off" />
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="submitForm">wen儿wo喔wen儿wo喔</el-button>
            </el-form-item>
        </el-form>
    </div>
</template>
<script setup lang="ts">
import { reactive } from 'vue';
import type { FormRules } from 'element-plus';
import { carOut, carMoney } from "@/api/car";
import { ElMessage } from 'element-plus';
import { ElNotification } from "element-plus";
const cars = reactive({
    carId: "",
    vip: ""
})
// 自定义车牌校验
const validatePass = (rule: any, value: any, callback: any) => {
    if (!/^\w{5,10}$/.test(value)) {
        callback(new Error("车牌号5-10位"));
    } else {
        callback();
    }
}
const rules = reactive<InstanceType<typeof FormRules>>({
    carId: [{ required: true, validator: validatePass, trigger: 'blur' }],
    vip: [{ required: true, message: "这里不能是空的哦", trigger: 'blur' }],
})
function submitForm() {
    carOut({
        carnumber: cars.carId,
        isvip: cars.vip
    }).then(resp => {
        if (resp.data.code == 20000) {
            console.log(resp.data.data[0].money);
            
            ElMessage({
                message: '小车车走啦~',
                type: 'success',
            })
            if (cars.vip == "否") {
                carMoney({
                    money: parseInt(resp.data.data[0].money),
                    carnumber: cars.carId,
                    name: localStorage.getItem("adminname")
                }).then(resp1 => {
                    if (resp1.data.code == 20000) {
                        console.log(resp1);
                        
                        ElNotification({
                            message: resp1.data.msg,
                            type: 'success',
                        })
                    }
                })
            }
            cars.carId = "";
            cars.vip = "";
        } else if (resp.data.code == 50000) {
            ElMessage.error("你的车车不在我们停车场~")
        }
    })
}
</script>